package com.smart.village.big.screen.controller.bigscreen;

import com.alibaba.fastjson.JSONObject;
import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.ShopService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 数智商城数据接口
 */
@Tag(name = "数智商城数据接口")
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @Operation(summary = "商家展示")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
    })
    @GetMapping("/getShopList")
    @ResponseBody
    public AjaxResult getShopList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String category,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(shopService.getShopList(townNumber, villageNumber, category, pageNum, pageSize));
    }

    @Operation(summary = "商家展示-详情")
    @Parameters({
            @Parameter(name = "shopSerialNumber", description = "商家编码 必传")
    })
    @GetMapping("/getShopDetail")
    @ResponseBody
    public AjaxResult getShopDetail(
            @RequestParam String shopSerialNumber
    ) {
        return AjaxResult.success(shopService.getShopDetail(shopSerialNumber));
    }

    @Operation(summary = "商家展示-分类")
    @GetMapping("/getShopListByCategory")
    @ResponseBody
    public AjaxResult getShopListByCategory() {
        return AjaxResult.success(shopService.getShopListByCategory());
    }

    @Operation(summary = "商家展示-点位信息")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "category", description = "分类编码-非必填", required = false)
    })
    @GetMapping("/getShopCoordsList")
    @ResponseBody
    public AjaxResult getShopCoordsList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String category
    ) {
        return AjaxResult.success(shopService.getShopCoordsList(townNumber, villageNumber, category));
    }

    @Operation(summary = "事件分类")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getEventCategory")
    @ResponseBody
    public AjaxResult getEventCategory(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(shopService.getEventCategory(townNumber, villageNumber, pageNum, pageSize));
    }

    @Operation(summary = "事件详情")
    @Parameters({
            @Parameter(name = "complaintId", description = "事件id 必传"),
    })
    @GetMapping("/getComplaintsDetail")
    @ResponseBody
    public AjaxResult getComplaintsDetail(
            @RequestParam String complaintId
    ) {
        try {
            JSONObject resultJson = shopService.getComplaintsDetail(complaintId);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "全网搜索")
    @Parameters({

    })
    @GetMapping("/getGlobalSearch")
    @ResponseBody
    public AjaxResult getGlobalSearch(

    ) {
        return AjaxResult.success(shopService.getGlobalSearch());
    }

    @Operation(summary = "消费者满意度")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
    })
    @GetMapping("/getShopSatisfaction")
    @ResponseBody
    public AjaxResult getShopSatisfaction(
            @RequestParam String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        return AjaxResult.success(shopService.getShopSatisfaction(townNumber, villageNumber));
    }

    @Operation(summary = "消费者满意度-二级页面")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "satisfaction", description = "满意度 0 不满意 1 满意"),
    })
    @GetMapping("/getShopSatisfactionDetail")
    @ResponseBody
    public AjaxResult getShopSatisfactionDetail(
            @RequestParam String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String satisfaction
    ) {
        return AjaxResult.success(shopService.getShopSatisfactionDetail(townNumber, villageNumber, satisfaction));
    }

    @Operation(summary = "商家排名")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
    })
    @GetMapping("/getShopRank")
    @ResponseBody
    public AjaxResult getShopRank(
            @RequestParam String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(shopService.getShopRank(townNumber, villageNumber, pageNum, pageSize));
    }

    @Operation(summary = "新媒体运营")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "haveShop", description = "是否有店 0 没店 1 有店"),
    })
    @GetMapping("/getNewMedia")
    @ResponseBody
    public AjaxResult getNewMedia(
            @RequestParam String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String haveShop,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        return AjaxResult.success(shopService.getNewMedia(townNumber, villageNumber, haveShop, pageNum, pageSize));
    }
}
